package model;

import init.DBManagement;

import java.util.Vector;

import model.beans.MateriaBean;

public class Subject {
	public static MateriaBean instance( String str_subjectCode, String str_academyCode ){
		MateriaBean subject_retVal = null;
		String str_instance = 
			" select NOMBRE "+
			" from	 BASMATB "+
			" where  CLAVE = '"+str_subjectCode+"' ";
		DBManagement database = new DBManagement();
	    database.executeQuery( str_instance );
	    if( database.getNumRows() == 1 ){
	    	subject_retVal = new MateriaBean();
	    	subject_retVal.setCodigo(str_subjectCode);
	    	subject_retVal.setAcademia(str_academyCode);
	    	subject_retVal.setNombre(database.getItem(0, 0));
	    }
	    database = null;
		return subject_retVal;
	}
	
	public static Vector list(String str_academyCode){
		Vector vec_retVal = new Vector();
		String str_list = 
			" SELECT CLAVE, "+
			"		 NOMBRE "+
			" FROM	 BASACMR "+
			"		 	INNER JOIN BASMATB "+
			"			ON CLAVE = MATERIA_TK "+
			" WHERE  ACADEMIA_TK = '"+str_academyCode+"'";
		DBManagement database = new DBManagement();
	    database.executeQuery( str_list );
	    for( int int_i = 0; int_i < database.getNumRows(); int_i++){
	    	MateriaBean subject = new MateriaBean();
	    	subject.setCodigo(database.getItem(int_i, 0));
	    	subject.setNombre(database.getItem(int_i, 1));
	    	subject.setAcademia(str_academyCode);
	    	vec_retVal.add(subject);
	    }
	    database = null;
		return vec_retVal;
	}
}
